package com.test.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public final class IOUtils {

	private static final int DEFAULT_BUFFER_SIZE = 1024;

	private IOUtils() {
	}

	public static void saveStreamToFile(InputStream inputStream, String fileName) throws IOException {
		File file = new File(fileName);

		OutputStream out = new FileOutputStream(file);

		int read = 0;
		byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];

		while ((read = inputStream.read(bytes)) != -1) {
			out.write(bytes, 0, read);
		}

		inputStream.close();
		out.flush();
		out.close();
	}
}
